<?php

class LikesController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function getIndex()
    {
        $video_id = isset($_GET['video_id'])?$_GET['video_id']:null;
        $nerds = Likes::join('profile', 'likes.user_id', '=', 'profile.user_id')
                        ->where('video_id', '=', $video_id)
                        ->select('video_id','profile.user_id','profile.fullname','profile.profile_picture')
                        ->paginate(5);

        return Response::json(array('status' => 'success', 'state' => $nerds->toArray()), 200);
    }

//    /**
//     * Show the form for creating a new resource.
//     *
//     * @return Response
//     */
//    public function getCreate()
//    {
//        return View::make('upload.upload', array('num' => str_random(8)));
//    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function postCreate()
    {
        // validate
        // read more on validation at http://laravel.com/docs/validation
        // store
        $like = new Likes;
        $like->video_id = 26;
        $like->user_id = 1;
        // TODO: 这里的user_id 对应登录的人，需要重新修改
        $like->save();
        return Response::json('success', 200); // or do a redirect with some message that file was uploaded
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $video_id
     * @return Response
     */
    public function getShow($video_id)
    {
        // get the nerd
        $nerd = Likes::find($video_id);

        // show the view and pass the nerd to it
        return Response::json(array('status' => 'success', 'state' => $nerd), 200);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function getEdit($id)
    {
        return Response::json(array('status' => 'success', 'state' => "edit page"), 200);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function postUpdate($id)
    {
        // validate
        // read more on validation at http://laravel.com/docs/validation
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function postDestroy($id)
    {
        // delete
        $nerd = Likes::find($id);
        $nerd->delete();

        // redirect
        return Response::json('success', 200);
    }
}